package lex.dm.ui.dt;

import javax.swing.table.AbstractTableModel;

import lex.dm.id3.IDataSet;

public class ClusteringTableModel extends AbstractTableModel
{
	private static final int DEFUAKT_K = 2;
	private static final String[] COLUMN_NAMES = { "Fields", "k" };
	private String[] fields = new String[0];
	private int[] k = new int[0];

	public int[] getK()
	{
		return k;
	}

	public void setDataSet( IDataSet dataSet )
	{
		int count = dataSet.getColumnCount();
		this.fields = new String[count];
		this.k = new int[count];
		java.util.Arrays.fill( k, DEFUAKT_K );
		k[count - 1] = 0;
		for( int i = 0; i < count; i++ )
			fields[i] = dataSet.getAttribute( i );
		this.fireTableDataChanged();
	}

	@Override
	public Class<?> getColumnClass( int column )
	{
		if( 0 == column )
			return String.class;
		else if( 1 == column )
			return Integer.class;
		else
			return super.getColumnClass( column );
	}

	@Override
	public String getColumnName( int column )
	{
		return COLUMN_NAMES[column];
	}

	@Override
	public boolean isCellEditable( int row, int column )
	{
		return 1 == column;
	}

	@Override
	public void setValueAt( Object value, int row, int column )
	{
		if( 1 == column )
			this.k[row] = (Integer) value;
	}

	@Override
	public int getColumnCount()
	{
		return COLUMN_NAMES.length;
	}

	@Override
	public int getRowCount()
	{
		return fields.length;
	}

	@Override
	public Object getValueAt( int row, int column )
	{
		if( 0 == column )
			return fields[row];
		else if( 1 == column )
			return k[row];
		else
			return null;
	}
}
